var basePath = getBasePath(); 
var modelName = "公告信息";

$(function(){
	  //显示权限按钮
	  var parentUUID = $("input[name='parentUUID']").val();
   	  $.permission.showButton(parentUUID,"actionBtnArea");
   	  
   	  //表格初始化
	  $.dataGridEasyUI.initTable({
		  pageId:"#noticeInfoListPage",
		  gridId:"#noticeInfoList",
		  url:getBasePath()+'noticeInfo/getNoticeInfoList.do',
		  toolbarId:"#noticeInfoListPage .tb_toolbar",
		  columns:[[
  		            {field:'id',checkbox:true},
  		            {field:'title',title:'标题',width:'22%',formatter: function(value,row,index){
	  		  	    	return "<a href='javascript:showDetail("+row.id+")' style='color:green'>"+value+"</a>";
					}},
  		            {field:'statTime',title:'生效时间 ',width:'15%',formatter: function(value,row,index){
	  		  	    	return "起始:"+row.startTime+"</br>结束:"+row.endTime;
  					  }
                    },
                    {field:'showType',title:'展示类型',width:'8%'},
                    {field:'noticeType',title:'所属分类',width:'8%'},
                    {field:'collectionTimes',title:'阅读/收藏',width:'5%',formatter: function(value,row,index){
	  		  	    	return row.readCount+"/"+row.collectionTimes+"";
					  }},
                    {field:'checkStatus',title:'审批状态及意见',width:'9%',formatter: function(value,row,index){
  						if (row.checkStatus==0){
  							return "<font color='#f58220'><b>待审核</b></font>";
  						} else if (row.checkStatus==1){
  							return "<font color='#7fb80e'><b>审核通过<br>审核意见："+row.checkMsg+"</b></font>";
  						} else if (row.checkStatus==2){
  							return "<font color='#d71345'><b>未通过<br>审核意见："+row.checkMsg+"</b></font>";
  						}
  					}},
  		            {field:'creater',title:'发布人',width:'8%'},
  		            {field:'createTime',title:'发布时间',width:'8%'}
  		        ]]
	  });
  
  //新增按钮绑定事件
  $("#addDataLink").bind("click",function(){
	  window.location.href=getBasePath()+"manage/notice/editNoticeInfo.jsp";
	  /*$.dataGridEasyUI.initEditWindow({
		  url:getBasePath()+"manage/notice/editNoticeInfo.jsp",
		  title:"添加"+modelName+"信息",
		  actionType:"add"
	  });*/
  });
  
  //更新按钮绑定事件
  $("#updateDataLink").bind("click",function(){
	  $.dataGridEasyUI.initEditWindow({
		  url:getBasePath()+"manage/notice/editNoticeInfo.jsp?showType=window",
		  title:"编辑"+modelName+"",
		  windowType:"iframe",
		  actionType:"update",
		  width: 865,
		  height: 535
	  });
  });
  
  //批量删除
  $("#batchDeleteLink").bind("click",function(){
	  $.dataGridEasyUI.batchDeleteData({
		  url:getBasePath()+"/noticeInfo/batchDelNoticeInfoForHS.do",
	  });
  });
  
  //单个删除
  $("#singleDeleteLink").bind("click",function(){
	  $.dataGridEasyUI.batchDeleteData({
		  url:getBasePath()+"/noticeInfo/delNoticeInfo.do",
	  });
  });


   //图片弹窗
	$(".fancybox-effects-a").fancybox({
		helpers: {
			title : {
				type : 'outside'
			},
			overlay : {
				speedOut : 0
			}
		}
	});
})

//查看详细信息
function showDetail(id){
  $.dataGridEasyUI.initEditWindow({
	  url:getBasePath() + "noticeInfo/getNoticeInfoDetail.do?id="+id,
	  title:"查看"+modelName+"明细",
	  actionType:"detail",
	  width: $(window).width()*0.95,
	  height: $(window).height()*0.95
  })
}

//审核信息
function checkSingleData(){
	$.dataGridEasyUI.initEditWindow({
		  url:getBasePath() + "manage/notice/checkNotice.jsp",
		  title:"审核"+modelName,
		  actionType:"check",
	      width: 650,
          height: 300
	});
}

//检索数据
function seachData(){
   var searChObj = new Object(); 
   var formId = "searchForm";
   $("#"+formId).find("input").each(function(i){
	   searChObj[$(this).attr("name")] = $(this).val();
   });
   
   $("#"+formId).find("select").each(function(i){
	   searChObj[$(this).attr("name")] = $(this).val();
   });
   tableObject.datagrid({
	     queryParams:searChObj
   })
}

//永久删除数据
function batchDelInDB(){
  $.dataGridEasyUI.batchDeleteInDB({
	  url:getBasePath()+"/noticeInfo/batchDelNoticeInfo.do",
  });
}
         
         
 //恢复数据
function rebackData(){
	$.dataGridEasyUI.batchDeleteInDB({
		  url:basePath+"/noticeInfo/batchRebackData.do"
	});
}
